// 封装购物车相关接口

import httpInstance from "@/utils/http"

// 封装加入购物车
export const insertCartAPI = ({ skuId, count }) => {
  return httpInstance({
    url: '/member/cart',
    method: 'POST',
    data: {
      skuId,
      count
    }
  })
}

// 封装获取购物车列表
export const findCartListAPI = () => {
  return httpInstance({
    url: '/member/cart'
  })
}

// 封装删除购物车商品
export const delCartAPI = (ids) => {
  return httpInstance({
    url: '/member/cart/',
    method: 'DELETE',
    data: {
      ids
    }
  })
}

// 合并购物车
export const mergeCartAPI = (data) => {
  return httpInstance({
    url: '/member/cart/merge',
    method: 'POST',
    data
  })
}

// 修改购物车商品的状态和数量
export const updateCartAPI = ({ skuId, selected, count }) => {
  return httpInstance({
    url: `/member/cart/${skuId}`,
    method: 'PUT',
    data: {
      selected,
      count
    }
  })
}

// 全选/取消 购物车商品
export const updateSelectCartAPI = ({ selected, ids }) => {
  return httpInstance({
    url: '/member/cart/selected',
    method: 'PUT',
    data: {
      selected,
      ids
    }
  })
}
